package com.java.controller;

import com.java.model.Booking;
import com.java.model.Result;
import com.java.service.BookingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
@RequestMapping("/booking")
public class BookingController {

    @Autowired
    private BookingService bookingService;

    /**
     * 后台预约单跳转页面
     * @return
     */
    @GetMapping("/list")
    public String list() {
        return "/booking/list";
    }

    /**
     * 后台预约单跳转页面
     * @return
     */
    @GetMapping("/list2")
    public String list2() {
        return "/booking/list2";
    }

    /**
     * 后台预约单查询列表
     * @param booking
     * @return
     */
    @PostMapping("toList")
    @ResponseBody
    public Result toList(Booking booking) {
        return bookingService.list(booking);
    }

    /**
     * 点击同意后将预约单状态改为2已投放
     * @return
     */
    @PostMapping("/yes")
    @ResponseBody
    public Result yes(Booking booking) {
        booking.setStatus(2);
        booking.setBookingTime(new Date());
        bookingService.yes(booking);
        return Result.success();
    }

    /**
     * 点击同意后将预约单状态改为4已投放
     * @return
     */
    @PostMapping("/no")
    @ResponseBody
    public Result no(Booking booking) {
        booking.setStatus(4);
        booking.setBookingTime(new Date());
        bookingService.no(booking);
        return Result.success();
    }

}
